﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zebra.Utility;

namespace Zebra.WinFramework
{   
    public partial class BaseButton : UserControl
    {
        public bool Success = false;

        public event EventHandler SaveClick;
        public event EventHandler DeleteClick;
        public event EventHandler NewClick;
        public event EventHandler ResetClick;

        public BaseButton()
        {
            InitializeComponent(); 
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (SaveClick != null)
            {
                try
                {
                    SaveClick(sender, e);
                    this.Success = true;
                }
                catch(Exception ex)
                { 
                    this.Success = false;
                     Logger.Error(typeof(BaseButton), ex.ToString());
                }

                if (this.Success)
                {

                    MsgBoxHelper.Show(CoreMessages.SaveSuccess, CoreMessages.Successful, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MsgBoxHelper.Show(CoreMessages.SaveFailed, CoreMessages.Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (DeleteClick != null)
            {
                if (MessageBox.Show(CoreMessages.DeleteAsk, CoreMessages.DeleteAsk, MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    try
                    {
                        DeleteClick(sender, e);
                        this.Success = true;
                    }
                    catch (Exception ex)
                    {
                        this.Success = true;
                        Logger.Error(typeof(BaseButton), ex.ToString());
                    }

                    if (this.Success)
                    {
                        MsgBoxHelper.Show(CoreMessages.DeleteSuccess, CoreMessages.Successful, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MsgBoxHelper.Show(CoreMessages.DeleteFailed, CoreMessages.Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            if (NewClick != null)
            {
                NewClick(sender, e);
            }
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            if (ResetClick != null)
                ResetClick(sender, e);
        }
    }
}
